<script>import {request} from '@/utils/request.js'
	import {storageData} from '@/utils/storageData.js'
	export default {
		globalData: {
			wechatOpenId: '',
			unionId: '',
			loginUser: {}
		},
		onLaunch: function() {
			console.log('App Launch')
			
			const options = uni.getLaunchOptionsSync()
			console.log(options)
			const shareUc = options.query.shareUc
			console.log(shareUc)
			// 获取微信用户的WechatOpenId
			const $this = this
			uni.login({
			  provider: 'weixin', //使用微信登录
			  success: function (loginRes) { 
			    console.log(loginRes)
					request.post(  
						'/wechatMini/login', { code: loginRes.code , miniType: 'math' , shareUc: shareUc }
					).then(res => {
						console.log('获取微信openId成功')
						console.log(res)
						$this.globalData.wechatOpenId = res.openId
						$this.globalData.unionId = res.unionId
						$this.globalData.loginUser = res.user
						storageData.saveLoginUser(res.user)
						console.log($this.globalData.loginUser)
					}).catch(err => {
						console.log(err)
					})
			  }
			})
		},
		onShareAppMessage(res) {
			const userInfo = storageData.getLoginUser()
			if (res.from === 'button') {
					 // 来自页面内分享按钮
					 console.log(res.target);
			}
			return {
				title: '萌芽学口算：学习好帮手',
				path: '/pages/index/index?shareUc=' + userInfo.userCode,
				mpId: 'wxe9f0922a16331d4b', //此处配置微信小程序的AppId
				imageUrl: 'https://fcz.oss-cn-beijing.aliyuncs.com/images/myxb.png'
			}
		},
		onShareTimeline(res) {
			const userInfo = storageData.getLoginUser()
			return {
				title: '萌芽学口算：学习好帮手',
				path: '/pages/index/index?shareUc=' + userInfo.userCode,
				mpId: 'wxe9f0922a16331d4b', //此处配置微信小程序的AppId
				imageUrl: 'https://fcz.oss-cn-beijing.aliyuncs.com/images/myxb.png'
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	page{
		width: 100%;
		height: 100%;
		font-size: 14px;
		color: #333333;
	}
	uni-app, uni-page, uni-page-wrapper, uni-page-body{
		height: 100%;
	}
	
	.page_wrapper{
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	
	.page_sub_title{
		font-size: 17px;
		font-weight: 500;
		color: #333333;
		height: 60px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.green_btn{
		background: rgb(66, 185, 131);
		color: white;
	}
	
	.top_line{
		border-top: 1px solid #e2e2e2;
	}
	.bottom_line{
		border-bottom: 1px solid #e2e2e2;
	}
	
	.disabled_btn{
		background-color: darkgray!important;
	}
	
	/*
	tabbar : select : #36ab60
	tabbar : no select : #8a8a8a
	*/
</style>
